<template>
<div class="content-box">
    <e-heading>{{title}}</e-heading>
    <div class="add_class">
      <el-form :model="form" :rules="rules" ref="form" label-width="100px">
        <el-form-item label="课程名称：" prop="className" style="margin-bottom:13px">
          <span v-if="$route.query.isonly == 'yes'">{{$route.query.name}}</span>
          <el-select v-else v-model="form.className" value-key="id" placeholder="请选择课程" style="width: 550px;" :disabled="$route.query.isedit ? true :false" @change="handleGetschollType">
              <el-option v-for="item in train_selectclass_list" v-if="item.properties!=2" :key="item.id" :label="item.courseName" :value="item"></el-option>
          </el-select>
          <p class="cike-cant small" v-if="!($route.query.name || $route.query.isedit == 'edit')">（注：次课不可新增班级）</p>
        </el-form-item>
        <el-form-item label="校 区：" prop="campus">
          <el-select v-model="form.campus" value-key="key" placeholder="请选择校区" no-data-text="请先选择课程或到校区列表设置" style="width: 550px;" :disabled="$route.query.isedit ? true :false" @change="getAddress">
            <el-option v-for="item in train_scholl_type_list" :key="item.key" :label="item.value" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班 别：" prop="type">
          <el-select v-model="form.type" value-key="key" placeholder="请选择班别" style="width:550px;" :disabled="$route.query.isedit ? true :false">
            <el-option v-for="item in train_class_type_list" :key="item.key" :label="item.value" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="班级名称：" prop="name">
          <el-input :minlength="2" :maxlength="40" v-model="form.name" style="width:550px;"></el-input>
        </el-form-item>
        <el-form-item label="上课时间：" prop="time">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            :editable="false"
            align="right"
            format="yyyy-MM-dd"
            :clearable="false"
            @change="handleSelectTime"
            :disabled="$route.query.status == 1"
            :picker-options="pickerOptions"
            placeholder="选择日期范围"
            style="width:550px;">
          </el-date-picker>
        </el-form-item>
        <!--专业课-->
        <div class="specialty classTips" v-if="courseType == 0">
          <el-form-item label="课程教练：" prop="coach">
            <el-select v-model="form.coach" value-key="id" placeholder="请选择主教练" style="width: 550px;" 
              @change="handleAllCheckTeacher(1)" :disabled="$route.query.status == 1 || roleType == '99'">
              <el-option v-for="item in train_teacher_list" :key="item.id" :label="item.teacherName" :value="item"
                :disabled="checkCoachIsNotAssit(item, form.assistCoach)"></el-option>
            </el-select>
            <el-select v-model="form.assistCoach" value-key="id" placeholder="请选择助理教练" class="pro-coach" multiple
              @change="handleAllCheckTeacher(2, form.assistCoach)" :disabled="$route.query.status == 1">
              <el-option v-for="item in train_teacher_list" :key="item.id" :label="item.teacherName" :value="item"
              :disabled="form.coach.id === item.id || form.assistCoach.length >= 5"></el-option>
            </el-select>
            <el-select v-model="form.adviser" value-key="userId" placeholder="请选择顾问" class="pro-coach" multiple
              @change="handleAllCheckTeacher(3, form.adviser)" :disabled="$route.query.status == 1">
              <el-option v-for="item in train_adviser_list" :key="item.userId" :label="item.teacherName" :value="item"
                :disabled="form.adviser.length >=3"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="上课周期：" class="set_main is-required">
            <el-button class="set_button" type="link" @click="handlebatchShow('Professional')" v-if="$route.query.status != 1">批量设置</el-button>
            <el-row>
              <el-col :span="24" style="margin-bottom:18px;">
                <el-checkbox-group v-model="selectWeekCode" @change="setWeekdays">
                  <el-checkbox v-for="item in weekdays" :key="item.value" 
                  :label="item.value" 
                  :disabled="$route.query.status == 1 || item.isdisable">
                    {{item.name}}
                  </el-checkbox>
                </el-checkbox-group>
              </el-col>
            </el-row>
            <el-row v-for="(item, index) in form.classSeting" :key="index" v-if="item.isShow">
              <el-col :span="2" style="margin-bottom:0;">每{{Number(item.weekTime) | getWeekDay}}</el-col>
              <el-col :span="22" style="margin-bottom:0;" 
                v-for="(classItem, classIndex) in item.setArray" 
                :key="index+classIndex" 
                :offset="classIndex > 0 ? 2 : 0">
                <el-form-item label="" label-width="0px" :error="classItem.errorMsg" style="margin-bottom:20px;">
                  <el-row>
                    <el-col :span="7">
                      <el-form-item>
                        <el-time-picker
                          is-range
                          v-model="classItem.classTime"
                          format="HH:mm"
                          :clearable="false"
                          placeholder="选择上课时间"
                          @change="handleTimeSection(classItem.classTime, index, classIndex)"
                          :disabled="$route.query.status == 1"
                          style="width:185px;">
                        </el-time-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-select v-model="classItem.classAdd" value-key="id" placeholder="选择上课地点" style="width: 95%;" no-data-text="请先选择校区"
                         :disabled="$route.query.status == 1">
                        <el-option v-for="item in addressList" :key="item.id" :label="item.address" :value="item"></el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="2" v-if="$route.query.status != 1">
                      <el-button class="btn-icon" icon="plus" 
                        @click="handleAddClassItem(index, classIndex)" 
                        v-if="((classIndex == item.setArray.length - 1) || item.setArray.length == 1) && item.setArray.length < 4" 
                        :disabled="!(classItem.classTime && classItem.classAdd && classItem.isError == 2)"></el-button>
                      <el-button class="btn-icon" icon="minus" 
                        @click="handleRemoveClassItem(index, classIndex)" 
                        v-if="(classIndex != item.setArray.length - 1) && item.setArray.length != 1"></el-button>
                    </el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form-item>
        </div>

        <!--综合课-->
        <div v-else class="classTips">
          <el-form-item label="上课周期：" class="set_main is-required">
            <el-button class="set_button" type="link" @click="handlebatchShow('synthesis')" v-if="$route.query.status != 1">批量设置</el-button>
            <el-row>
              <el-col :span="24" style="margin-bottom:18px;">
                <el-checkbox-group v-model="selectWeekCode" @change="setWeekdays">
                  <el-checkbox 
                  v-for="item in weekdays" 
                  :key="item.value" 
                  :label="item.value" 
                  :disabled="$route.query.status == 1 || item.isdisable">{{item.name}}</el-checkbox>
                </el-checkbox-group>
              </el-col>
            </el-row>
            <el-row v-for="(item, index) in form.classSeting" :key="index" v-if="item.isShow">
              <el-col :span="2" class="mb0">每{{Number(item.weekTime) | getWeekDay}}</el-col>
              <el-col :span="22" class="mb0" 
                v-for="(classItem, classIndex) in item.setArray" 
                :key="index+classIndex" 
                :offset="classIndex > 0 ? 2 : 0">
                <el-form-item label="" label-width="0px" :error="classItem.errorMsg" style="margin-bottom:20px;">
                  <el-row>
                    <el-col :span="6">
                      <el-form-item>
                        <el-input :minlength="2" :maxlength="20" v-model="classItem.className" placeholder="请输入学科名称" style="width:95%;" :disabled="$route.query.status == 1"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item>
                        <el-time-picker  is-range
                          style="width: 162px;"
                          v-model="classItem.classTime"
                          format="HH:mm"
                          :clearable="false"
                          placeholder="选择上课时间"
                          @change="handleTimeSection(classItem.classTime, index, classIndex)"
                          :disabled="$route.query.status == 1">
                        </el-time-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-select v-model="classItem.classAdd" value-key="id" placeholder="选择上课地点" style="width: 95%;" no-data-text="请先选择校区" 
                        :disabled="$route.query.status == 1">
                        <el-option v-for="item in addressList" :key="item.id" :label="item.address" :value="item"></el-option>
                      </el-select>
                    </el-col>
                    
                    <el-col :span="2" v-if="$route.query.status != 1">
                      <el-button class="btn-icon" icon="plus" @click="handleAddClassItem(index, classIndex)" 
                        v-if="((classIndex == item.setArray.length - 1) || item.setArray.length == 1) && item.setArray.length < 4" 
                        :disabled="!(classItem.className && classItem.classTime && classItem.classAdd && classItem.classCoach && classItem.isError == 2)" 
                        :key="index+classIndex" />
                      <el-button class="btn-icon" icon="minus" @click="handleRemoveClassItem(index, classIndex)" 
                      v-if="(classIndex != item.setArray.length - 1) && item.setArray.length != 1" />
                    </el-col>
                    <el-col :span="16" class="add-coach">
                      <el-select v-model="classItem.classCoach" value-key="id" placeholder="请选择主教练" class="full-width" 
                        @change="handleCheckTeacher(index, classIndex)" :disabled="$route.query.status == 1">
                        <el-option v-for="item in train_teacher_list" :key="item.id" :label="item.teacherName" :value="item"
                          :disabled="checkCoachIsNotAssit(item, classItem.assistCoach)"></el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="16" class="add-coach">
                      <el-select v-model="classItem.assistCoach" value-key="id" placeholder="请选择助理教练" class="full-width" multiple
                        @change="handleCheckCoach(index, classIndex, 2)" :disabled="$route.query.status == 1">
                        <el-option v-for="item in train_teacher_list" :key="item.id" 
                        :label="item.teacherName" :value="item"
                        :disabled="classItem.classCoach.id === item.id || classItem.assistCoach.length>= 5"></el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="16" class="add-coach">
                      <el-select v-model="classItem.adviser" value-key="userId" placeholder="请选择顾问" class="full-width" multiple
                        @change="handleCheckCoach(index, classIndex, 3)" :disabled="$route.query.status == 1">
                        <el-option v-for="item in train_adviser_list" :key="item.userId" :label="item.teacherName" :value="item"
                        :disabled="classItem.adviser.length >=3"></el-option>
                      </el-select>
                    </el-col>
                  </el-row>
                  
                </el-form-item>
              </el-col>
            </el-row>
          </el-form-item>
        </div>
        
        <!--课时列表-->
        <div class="time_list">
          <el-row>
            <el-col :span="8" v-for="(item, index) in hourList" :key="index" :class="{'color_grea': item.status == 1}"><span class="num_trip">{{index + 1}}</span> {{item.dateTime + ' ' + item.weekDay + ' ' + item.monent}} <span v-if="$route.query.status != 1"><el-button type="text" v-if="item.status == 0" @click="handleDelteHour(index)">删除</el-button><el-button type="text" v-else @click="handleCancleHour(index)">恢复</el-button></span></el-col>
          </el-row>
          <div class="class_total">共<span class="total_green">{{hourList.length}}</span>课时<p style="display:inline-block;" v-if="deleteHour > 0">，已删除<span class="total_red">{{deleteHour}}</span>课时，还有<span class="total_green">{{hourList.length - deleteHour}}</span>课时</p></div>
        </div>
      </el-form>
      <div class="button-box">
        <el-button @click="goBackList">取 消</el-button>
        <el-button type="primary" @click="handleSubmit" :disabled="hourList.length - deleteHour == 0 || isSubmit">确 定</el-button>
      </div>
    </div>

    <!--批量设置-->
    <el-dialog
      title="批量设置"
      :visible.sync="dialogVisible"
      width="560px">
      <div class="seting_tips">
        <el-form label-width="120px">
          <el-form-item label="学科名称：" v-if="isSynthesis">
            <el-input :minlength="2" :maxlength="20" v-model="form.batchSet.className" placeholder="请输入学科名称" style="width:85%;"></el-input>
          </el-form-item>
          <el-form-item label="上课时间：">
            <el-time-picker
              is-range
              :clearable="false"
              format="HH:mm"
              v-model="form.batchSet.classTime"
              placeholder="选择上课时间" style="width: 85%;">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="上课地点：">
            <el-select v-model="form.batchSet.classAdd" value-key="id" placeholder="选择上课地点" no-data-text="请先选择校区" style="width: 85%;">
              <el-option v-for="item in addressList" :key="item.id" :label="item.address" :value="item"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="教练团队：" v-if="isSynthesis">
            <el-select 
              v-model="form.batchSet.classCoach" value-key="id" placeholder="请选择主教练" style="width: 85%;">
              <el-option v-for="item in train_teacher_list" :key="item.id" :label="item.teacherName" :value="item"
                :disabled="checkCoachIsNotAssit(item, form.batchSet.assistCoach)"></el-option>
            </el-select>            
            <el-select 
              v-model="form.batchSet.assistCoach" value-key="id" placeholder="请选择助理教练" class="multi-select-coach" multiple
              :disabled="$route.query.status == 1">
              <el-option v-for="item in train_teacher_list" :key="item.id" :label="item.teacherName" :value="item"
                :disabled="form.batchSet.classCoach.id === item.id || form.batchSet.assistCoach.length >= 5"></el-option>
            </el-select>
            <el-select
              v-model="form.batchSet.adviser" value-key="userId" placeholder="请选择顾问" class="multi-select-coach" multiple
              :disabled="$route.query.status == 1">
              <el-option v-for="item in train_adviser_list" :key="item.userId" :label="item.teacherName" :value="item"
              :disabled="form.batchSet.adviser.length >= 3"></el-option>
            </el-select>
          </el-form-item>
        </el-form> 
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleReset">重 置</el-button>
        <el-button type="primary" @click="handleBatchSet">确 定</el-button>
      </span>
    </el-dialog>
</div>
</template>
<script>
import trainApi from 'api/train'
import { mapGetters } from 'vuex'
import { parseTime } from 'utils'
export default {
  computed: {
    ...mapGetters({
      train_teacher_list: 'train_teacher_list',
      train_selectclass_list: 'train_selectclass_list',
      train_scholl_type_list: 'train_scholl_type_list',
      train_class_type_list: 'train_class_type_list',
      train_teacher_info: 'train_teacher_info',
      train_adviser_list: 'train_adviser_list'
    }),
    courseType: { // 课程类型 1代表综合课，0代表专业课
      get: function () {
        if (this.form.className && this.form.className.properties) {
          return this.form.className.properties
        }
        return Number(this.$route.query.courseType) || 0
      },
      set: function () {
      }
    }
  },
  beforeCreate () {
    this.$store.dispatch('train_teacher_list')
    this.$store.dispatch('train_selectclass_list')
    this.$store.dispatch('train_adviser_list')
  },
  created () {
    if (this.$route.query.isedit === 'edit') {
      this.isEditone = true
      trainApi.classEdit({
        id: this.$route.query.id
      }).then((res) => {
        this.defaultData = res.data
        this.setDefaultData()
      })
      let getWeeks = this.$route.query.weekdays.split(',')
      for (let days of getWeeks) {
        this.selectWeekCode.push(Number(days))
        this.getWeeks.push(Number(days))
      }
    }
  },
  mounted () {
    if (this.$route.query.thisid) {
      this.form.className = {id: Number(this.$route.query.thisid), courseName: ''}
      let scope = this
      setTimeout(function () {
        for (let i = 0; i < scope.train_selectclass_list.length; i++) { // 取的匹配课程上课时间范围
          if (scope.train_selectclass_list[i].id === Number(scope.$route.query.thisid)) {
            scope.form.className.startClassTime = scope.train_selectclass_list[i].startClassTime
            scope.form.className.endClassTime = scope.train_selectclass_list[i].endClassTime
            scope.form.className.properties = scope.train_selectclass_list[i].properties
          }
        }
        scope.handleGetschollType()
      }, 500)
    }
    for (let sitem of [1, 2, 3, 4, 5, 6, 7]) {
      this.form.classSeting.push({
        weekTime: sitem,
        weekCode: sitem,
        isShow: false,
        setArray: [
          {
            className: '',
            classTime: '',
            classAdd: '',
            classCoach: '', // 主教练
            assistCoach: [], // 助理教练
            adviser: [], // 顾问
            errorMsg: '',
            errorCoach: {
              main: [],
              assistant: [],
              adviser: []
            },
            isError: 2
          }
        ]
      })
    }
  },
  data () {
    return {
      title: '班级信息',
      isSubmit: false,
      defaultData: {},
      schoolList: [],
      gradeList: [],
      getWeeks: [],
      dialogVisible: false,
      isSynthesis: false, // 用于批量设置的formItem显示隐藏 true：综合课, false: 专业课
      roleType: localStorage.getItem('role_type'),
      pickerOptions: {
        disabledDate (time) {
          // return time.getTime() < Date.now() - 8.64e7
        }
      },
      weekdays: [
        {name: '每周一', value: 1, isdisable: true},
        {name: '每周二', value: 2, isdisable: true},
        {name: '每周三', value: 3, isdisable: true},
        {name: '每周四', value: 4, isdisable: true},
        {name: '每周五', value: 5, isdisable: true},
        {name: '每周六', value: 6, isdisable: true},
        {name: '每周日', value: 7, isdisable: true}
      ],
      selectWeekCode: [],
      isEditone: false,
      isClassSet: [],
      isError: false,
      form: {
        className: '',
        campus: '',
        type: '',
        name: '',
        time: [],
        coach: '',
        assistCoach: [],
        adviser: [],
        classSeting: [],
        batchSet: {
          className: '',
          classTime: '',
          classAdd: '',
          classCoach: '',
          assistCoach: [],
          adviser: []
        }
      },
      hourList: [],
      dataList: [],
      subList: [],
      listTeachers: [], // 助理教练和顾问列表
      addressList: [],
      deleteHour: 0,
      rules: {
        className: [
          { type: 'object', required: true, message: '请选择课程', trigger: 'change' }
        ],
        campus: [
          { type: 'object', required: true, message: '请选择校区', trigger: 'change' }
        ],
        type: [
          { type: 'object', required: true, message: '请选择班别', trigger: 'change' }
        ],
        name: [
          { required: true, message: '请输入班级名称', trigger: 'blur' }
        ],
        classType: [
          { required: true, message: '请选择课程类型', trigger: 'change' }
        ],
        time: [
          { required: true, message: '请选择上课时间' }
        ],
        coach: [
          {
            validator: (rule, value, callback) => {
              if (value) {
                callback()
              } else {
                callback(new Error('请选择课程教练, 主教练不能为空'))
              }
            },
            trigger: 'change'
          }
        ]
      },
      teacherRoleType: [
        {
          type: 1,
          label: '助理教练'
        },
        {
          type: 2,
          label: '顾问'
        }
      ]
    }
  },
  watch: {
    'form.classSeting': {
      handler () {
        if (!this.isEditone) {
          this.gethourData()
        }
        this.form.classSeting.forEach((item, index) => { // 实时显示教练校验
          if (item.isShow && item.setArray.length > 0) {
            item.setArray.forEach((sitem, index) => {
              let newArr = []
              for (let key in sitem.errorCoach) {
                if (sitem.errorCoach[key]) {
                  sitem.errorCoach[key].forEach(s => {
                    newArr.push(s)
                  })
                }
              }
              sitem.errorMsg = newArr.length ? newArr.map(item => item.teacherName).join('，') + '教练在此时间段已有课程，请重新设置' : sitem.errorMsg.includes('上下课') ? sitem.errorMsg : ''
            })
          }
        })
        // this.getsubData()
      },
      deep: true
    },
    'form.type': function (val, oldVal) {
      if (oldVal) { // 切换班别，清空上课地点
        for (let item of this.form.classSeting) {
          for (let sitem of item.setArray) {
            sitem.classAdd = ''
          }
        }
      }
    },
    'form.className': function () {
      this.courseType = this.form.className.properties
      if (!this.isEditone) {
        this.selectWeekCode = []
        this.form.classSeting = [1, 2, 3, 4, 5, 6, 7].map((item) => {
          return {
            weekTime: item,
            weekCode: item,
            isShow: false,
            setArray: [
              {
                className: '',
                classTime: '',
                classAdd: '',
                classCoach: '', // 主教练
                assistCoach: [], // 助理教练
                adviser: [], // 顾问
                errorMsg: '',
                errorCoach: {
                  main: [],
                  assistant: [],
                  adviser: []
                },
                isError: 2
              }
            ]
          }
        })
      }
    }
  },
  methods: {
    handlebatchShow (type) {
      if (this.selectWeekCode.length === 0) {
        this.$alert('请先勾选上课周期', '温馨提示', {
          confirmButtonText: '确定',
          callback: action => {
          }
        })
      } else {
        this.isSynthesis = type === 'synthesis'
        this.dialogVisible = true
      }
    },
    goBackList () {
      this.$router.push({path: '/training/class'})
    },
    /*
     专业课教练校验
     roleType: 教练类型， 1代表主教练，2代表助教，3代表顾问
    */
    handleCheckProfessionalTeacher (index, classIndex, roleType) {
      if (this.form.campus && this.form.type && this.form.time[0]) { // 设置了时间
        let $item = this.form.classSeting[index].setArray[classIndex]
        if (roleType === 1) {
          if (this.form.coach) {
            this.checkTeacher(this.form.coach.id, index, classIndex)
          }
        } else if (roleType === 2) {
          if (this.form.campus && this.form.type && this.form.time[0]) {
            if (this.form.assistCoach.length) {
              let teacherIdList = []
              this.form.assistCoach.forEach(item => {
                if (item && item.id) {
                  teacherIdList.push(item.id)
                }
              })
              this.checkTeacher(teacherIdList, index, classIndex, 2)
            } else { // 没有选择助教
              let $errorCoach = this.getValidErrorCoach($item, 'assistant')
              $item.errorCoach['assistant'] = $errorCoach
            }
          }
        } else if (roleType === 3) {
          if (this.form.campus && this.form.type && this.form.time[0]) {
            if (this.form.adviser.length) {
              let teacherIdList = []
              this.form.adviser.forEach(item => {
                if (item && item.userId) {
                  teacherIdList.push(item.userId)
                }
              })
              this.checkTeacher(teacherIdList, index, classIndex, 3)
            } else { // 没有选择顾问
              let $errorCoach = this.getValidErrorCoach($item, 'adviser')
              $item.errorCoach['adviser'] = $errorCoach
            }
          }
        }
      }
    },
    handleCheckTeacher (index, classIndex, roleType = 1) { // 综合课校验主教练
      if (this.form.classSeting[index].setArray[classIndex].classCoach === '') {
        return false
      }
      if (!(this.form.campus && this.form.type && this.form.time[0] && this.form.classSeting[index].setArray[classIndex].classTime[0])) {
      } else {
        if (roleType === 2 || roleType === 3) { // 专业课或者综合课
          this.handleCheckCoach(index, classIndex, roleType)
        } else { // 综合课
          this.checkTeacher(this.form.classSeting[index].setArray[classIndex].classCoach.id, index, classIndex, roleType)
        }
      }
    },
    getValidErrorCoach ($item, key) {
      let ids = []
      let result = []
      // main: [], // 主教练
      // assistant: [], // 助教
      // adviser: [] // 顾问
      if ($item.errorCoach) {
        $item.errorCoach[key] = $item.errorCoach[key] || []
        if (this.courseType === 0) { // 专业课
          let assistCoachIds = this.form.assistCoach.map(item => item && item.id)
          let adviserCoachIds = this.form.adviser.map(item => item && item.userId)
          result = $item.errorCoach[key].filter(item => {
            return item.id === (this.form.coach || {}).id || assistCoachIds.indexOf(item.id) > -1 || adviserCoachIds.indexOf(item.id) > -1
          })
        } else { // 综合课
          let assistCoachIds = $item.assistCoach.map(item => item && item.id)
          let adviserCoachIds = $item.adviser.map(item => item && item.userId)
          result = $item.errorCoach[key].filter(item => {
            return item.id === ($item.classCoach || {}).id || assistCoachIds.indexOf(item.id) > -1 || adviserCoachIds.indexOf(item.id) > -1
          })
        }
      }
      return result.filter(item => { // 去重
        if (ids.indexOf(item.id) === -1) {
          ids.push(item.id)
          return true
        } else {
          return false
        }
      })
    },
    checkTeacher (teacherid, index, classIndex, roleType) { // 教练校验请求
      if (this.form.time[0] && this.form.classSeting[index].setArray[classIndex].classTime[0] && this.isError) {
        let $item = this.form.classSeting[index].setArray[classIndex]
        if (typeof teacherid === 'number') {
          trainApi.checkTeacher({
            courseType: this.form.className.properties || this.courseType, // 课程类型
            cycleId: this.form.classSeting[index].setArray[classIndex].id,
            courseId: this.form.className.id, // 课程 Id
            schoolId: this.form.campus.key, // 校区 ID
            weekCode: this.form.classSeting[index].weekCode, // 周几
            teacherId: teacherid,
            addressId: this.form.classSeting[index].setArray[classIndex].classAdd.id, // 上课地点 ID
            beginTimeStr: parseTime(this.form.time[0], '{y}-{m}-{d}'),
            endTimeStr: parseTime(this.form.time[1], '{y}-{m}-{d}'),
            classBeginTimeStr: parseTime(this.form.classSeting[index].setArray[classIndex].classTime[0], '{h}:{i}'), // 上课时间
            classEndTimeStr: parseTime(this.form.classSeting[index].setArray[classIndex].classTime[1], '{h}:{i}') // 下课时间
          }).then((res) => {
            let $errorCoachMain = this.getValidErrorCoach($item, 'main')
            if (res.data) {
              let teacher = this.train_teacher_list.filter(item => {
                return item.id === teacherid
              })[0]
              $errorCoachMain.every(item => item.id !== teacherid) && $errorCoachMain.unshift({
                ...teacher
              })
            }
            if ($item.errorCoach) {
              $item.errorCoach['main'] = $errorCoachMain
            }
          })
        } else { // typeof teacherid == [object array]
          if (roleType === 2 || roleType === 3) { // 2:助教，3：顾问
            // debugger
            let self = this
            let TerType = roleType === 2 ? 'assistant' : 'adviser'
            let $errorCoach = this.getValidErrorCoach($item, TerType)
            teacherid.forEach(assist => {
              let checkObj = {
                courseType: this.form.className.properties || this.courseType, // 课程类型
                cycleId: this.form.classSeting[index].setArray[classIndex].id,
                courseId: this.form.className.id, // 课程 Id
                schoolId: this.form.campus.key, // 校区 ID
                weekCode: this.form.classSeting[index].weekCode, // 周几
                userType: roleType,
                addressId: this.form.classSeting[index].setArray[classIndex].classAdd.id, // 上课地点 ID
                beginTimeStr: parseTime(this.form.time[0], '{y}-{m}-{d}'),
                endTimeStr: parseTime(this.form.time[1], '{y}-{m}-{d}'),
                classBeginTimeStr: parseTime(this.form.classSeting[index].setArray[classIndex].classTime[0], '{h}:{i}'), // 上课时间
                classEndTimeStr: parseTime(this.form.classSeting[index].setArray[classIndex].classTime[1], '{h}:{i}') // 下课时间
              }
              if (roleType === 3) {
                checkObj.userId = assist
                checkObj.userType = 2
              } else {
                checkObj.teacherId = assist
                checkObj.userType = 1
              }
              ((data) => {
                trainApi.checkTeacher(data).then((res) => {
                  if (res.data) {
                    if (data.userType === 1) {
                      self.train_teacher_list.forEach(item => {
                        if (item.id === data.teacherId && $errorCoach.every(_item => _item.id !== data.teacherId)) {
                          $errorCoach.push({
                            teacherName: item.teacherName,
                            id: item.id
                          })
                        }
                      })
                    } else {
                      self.train_adviser_list.forEach(item => {
                        if (item.userId === data.userId && $errorCoach.every(_item => _item.id !== data.userId)) {
                          $errorCoach.push({
                            teacherName: item.teacherName,
                            id: item.userId
                          })
                        }
                      })
                    }
                  }
                  if ($item.errorCoach) {
                    $item.errorCoach[TerType] = $errorCoach
                  }
                })
              })(checkObj)
            })
          }
        }
      }
    },
    setDefaultData () { // 编辑时设置初始数据
      this.form.className = {id: this.defaultData.courseId, courseName: ''}
      this.form.name = this.defaultData.name
      this.form.time = this.defaultData.beginTime ? [new Date(Number(this.defaultData.beginTime)), new Date(Number(this.defaultData.endTime))] : []
    },
    setWeekdays () { // 勾选上课周期
      this.selectWeekCode = this.selectWeekCode.sort((a, b) => {
        return a - b
      })
      this.setStratClassList()
    },
    handleGetschollType () { // 根据课程ID获取校区班别数据
      this.form.campus = ''
      this.form.type = ''
      if (this.form.className) {
        this.$store.dispatch('train_scholl_type_list', {courseId: this.form.className.id})
        this.$store.dispatch('train_class_type_list', {courseId: this.form.className.id})
        this.setStratClassList()
        if (this.$route.query.isedit === 'edit') { // 编辑时教师数据
          for (let i of this.train_selectclass_list) {
            if (i.id === this.defaultData.courseId) {
              this.form.className.properties = i.properties
            }
          }
          if (this.form.className.properties === 0) { // 专业课
            if (this.$route.query.weekdays) {
              this.form.coach = {id: this.defaultData.listCourseCycle[0].teacherId, value: ''}
            }
            let listClassTeacher = this.defaultData.listClassTeacher || []
            if (listClassTeacher.length) {
              listClassTeacher.forEach(item => {
                if (item.roleType === 1) { // 助教
                  this.form.assistCoach.push({
                    id: item.teacherId,
                    teacherName: item.teacherName,
                    userId: item.userId
                  })
                } else {
                  this.form.adviser.push({
                    id: item.teacherId,
                    teacherName: item.teacherName,
                    userId: item.userId
                  })
                }
              })
            }
          }
          this.form.campus = {key: this.defaultData.schoolId, value: ''}
          this.form.type = {key: this.defaultData.classesId, value: ''}
        }
        if (this.roleType === '99' && this.$route.query.isedit !== 'edit') { // 教练员默认设置自己
          this.form.coach = {id: this.train_teacher_info.id, teacherName: this.train_teacher_info.name}
          this.form.batchSet.classCoach = {id: this.train_teacher_info.id, teacherName: this.train_teacher_info.name}
          let classSeting = this.form.classSeting
          for (let item of classSeting) {
            let setArray = item.setArray
            for (let smItem of setArray) {
              smItem.classCoach = {id: this.train_teacher_info.id, teacherName: this.train_teacher_info.name}
            }
          }
        }
      }
    },
    setStratClassList () { // 设置默认上课周期数据
      if (this.form.className) {
        for (let item of this.train_selectclass_list) {
          if (item.id === this.form.className.id) {
            let codeArr = this.selectWeekCode
            for (let hitem of this.form.classSeting) {
              this.$set(hitem, 'isShow', false)
              for (let sitem of codeArr) {
                if (hitem.weekCode === sitem) {
                  this.$set(hitem, 'isShow', true)
                }
              }
            }
          }
        }
        if (this.$route.query.isedit === 'edit' && this.isEditone) { // 编辑设置初始值
          let classTimelist = this.defaultData.listCourseCycle
          for (let hitem of this.form.classSeting) {
            if (this.getWeeks.includes(hitem.weekCode)) {
              hitem.setArray = []
            } else {
              hitem.setArray = [
                {
                  className: '',
                  classTime: '',
                  classAdd: '',
                  classCoach: '',
                  assistCoach: [],
                  errorCoach: {
                    main: [],
                    assistant: [],
                    adviser: []
                  },
                  adviser: [],
                  errorMsg: '',
                  isError: 2
                }
              ]
            }
            setTimeout(() => {
              for (let i = 0; i < classTimelist.length; i++) { // 编辑时设置初始上课周期数据
                if (classTimelist[i] && classTimelist[i].weekCode === Number(hitem.weekCode)) {
                  let listTeachers = classTimelist[i].listTeachers || []
                  let assist = []
                  let adviser = []
                  listTeachers.forEach(item => {
                    if (item.roleType === 1) {
                      assist.push({
                        id: item.teacherId,
                        teacherName: item.teacherName
                      })
                    } else if (item.roleType === 2) {
                      adviser.push({
                        id: item.teacherId,
                        teacherName: item.teacherName,
                        userId: item.userId
                      })
                    }
                  })
                  classTimelist[i].isShow = true
                  hitem.setArray.push({
                    className: classTimelist[i].subjectName,
                    classTime: [new Date(classTimelist[i].beginTime), new Date(classTimelist[i].endTime)],
                    classAdd: {id: classTimelist[i].addressId, address: ''},
                    classCoach: {id: classTimelist[i].teacherId, teacherName: ''},
                    assistCoach: assist,
                    adviser: adviser,
                    errorCoach: {
                      main: [],
                      assistant: [],
                      adviser: []
                    },
                    errorMsg: '',
                    isError: 2,
                    id: classTimelist[i].id
                  })
                }
              }
            }, 300)
          }
        }
      }
    },
    getAddress () { // 根据校区获取上课地址
      if (this.form.campus) {
        trainApi.getAddress({
          schoolId: this.form.campus.key
        }).then((res) => {
          this.addressList = res.data
          if (!this.isEditone) {
            let classSeting = this.form.classSeting
            for (let item of classSeting) {
              let setArray = item.setArray
              for (let smItem of setArray) {
                smItem.classAdd = ''
              }
            }
          }
        })
      }
    },
    handleAllCheckTeacher (roleType, teachers) { // 校验所有上课时间
      for (let i = 0; i < this.form.classSeting.length; i++) { // 一星期的每一天
        let day = this.form.classSeting[i]
        if (day.isShow) {
          for (let si = 0; si < this.form.classSeting[i].setArray.length; si++) { // 每一天的每个时段
            this.checkTeaching(i, si, roleType)
          }
        }
      }
    },
    checkTeaching (index, classIndex, roleType = 1) { // 教练上课时间校验
      if (this.form.className.properties === 0 || this.courseType === 0) { // 专业课
        // debugger
        this.handleCheckProfessionalTeacher(index, classIndex, roleType)
      } else {
        this.handleCheckTeacher(index, classIndex, roleType)
      }
    },
    handleTimeSection (val, index, classIndex) { // 时间区间限制08:00-22:00&&一天之内课时不能重复
      if (val && (parseTime(val[0], '{h}:{i}') < '08:00' || parseTime(val[1], '{h}:{i}') > '22:00')) {
        this.form.classSeting[index].setArray[classIndex].errorMsg = '上下课时间范围为08:00-22:00'
        this.isError = false
        this.isSubmit = true
        this.form.classSeting[index].setArray[classIndex].classTime = []
      } else if (val && val[0]) {
        this.form.classSeting[index].setArray[classIndex].errorMsg = ''
        this.isSubmit = false
        this.isError = true
        if ((val[1].getTime() - val[0].getTime()) < 600000) {
          this.form.classSeting[index].setArray[classIndex].errorMsg = '上下课时间范围最小间隔为10分钟'
          this.isError = false
          this.isSubmit = true
        } else {
          this.form.classSeting[index].setArray[classIndex].errorMsg = ''
          this.isSubmit = false
          this.isError = true
          let isError = []
          for (let i = 0; i < this.form.classSeting[index].setArray.length; i++) {
            let item = this.form.classSeting[index].setArray[i]
            if (this.form.classSeting[index].setArray.length > 1 && classIndex !== 0) {
              if (classIndex !== i) {
                if (!(parseTime(val[0], '{h}:{i}') > parseTime(item.classTime[1], '{h}:{i}') || parseTime(val[1], '{h}:{i}') < parseTime(item.classTime[0], '{h}:{i}'))) {
                  isError.push(false)
                }
              }
            }
          }
          if (isError.includes(false)) {
            this.form.classSeting[index].setArray[classIndex].errorMsg = '上下课时间重复'
            this.isError = false
            this.isSubmit = true
            this.$set(this.form.classSeting[index].setArray[classIndex], 'isError', 1)
          } else {
            this.checkTeaching(index, classIndex, 1)
            this.checkTeaching(index, classIndex, 2)
            this.checkTeaching(index, classIndex, 3)
          }
        }
      }
    },
    getsubData () { // 转换提交数据
      let classSeting = this.form.classSeting
      this.subList = []
      for (let item of classSeting) {
        if (item.isShow) {
          // debugger
          let setArray = item.setArray
          for (let smItem of setArray) {
            if (smItem.className || smItem.classAdd) {
              if (this.courseType === 1) { // 综合课
                let listTeachers = []
                smItem.assistCoach.forEach(item => { // 助教
                  listTeachers.push({
                    roleType: 1,
                    teacherId: item.id
                  })
                })
                smItem.adviser.forEach(item => { // 顾问
                  listTeachers.push({
                    roleType: 2,
                    userId: item.userId
                  })
                })
                this.subList.push({
                  subjectName: smItem.className, // 学科名称
                  weekCode: item.weekCode, // 周几
                  beginTime: new Date(smItem.classTime[0]).getTime(),
                  endTime: new Date(smItem.classTime[1]).getTime(),
                  addressId: smItem.classAdd ? smItem.classAdd.id : '', // 上课地点 ID
                  teacherId: smItem.classCoach ? smItem.classCoach.id : '',
                  listTeachers: listTeachers
                })
              } else { // 专业课
                this.subList.push({
                  subjectName: smItem.className, // 学科名称
                  weekCode: item.weekCode, // 周几
                  beginTime: new Date(smItem.classTime[0]).getTime(),
                  endTime: new Date(smItem.classTime[1]).getTime(),
                  addressId: smItem.classAdd ? smItem.classAdd.id : '', // 上课地点 ID
                  teacherId: smItem.classCoach ? smItem.classCoach.id : ''
                })
              }
            }
          }
        }
      }
    },
    handleSubmit () { // 提交信息
      this.$refs['form'].validate((valid) => {
        if (this.isClassSet.includes(false)) {
          this.$message({
            type: 'warning',
            message: '上课周期不能为空'
          })
        } else {
          if (valid) {
            this.getsubData() // 提交时生成课程周期数据
            if (this.courseType !== 1) { // 专业课
              this.listTeachers = []
              this.form.assistCoach.forEach(item => { // 助教
                this.listTeachers.push({
                  roleType: 1,
                  teacherId: item && item.id
                })
              })
              this.form.adviser.forEach(item => { // 顾问
                this.listTeachers.push({
                  roleType: 2,
                  userId: item && item.userId
                })
              })
            }
            let params = {
              courseType: this.form.className.properties, // 课程类型
              courseId: this.form.className.id, // 课程 ID
              schoolId: this.form.campus.key,
              classesId: this.form.type.key, // 班别 Id
              name: this.form.name, // 班级名称
              beginTime: this.form.time[0].getTime(), // 开始时间
              endTime: this.form.time[1].getTime(), // 结束时间
              listCourseCycle: this.subList, // 课程周期列表
              listClassSchedule: this.hourList, // 班级课时列表
              teacherId: this.form.coach ? this.form.coach.id : '',
              removeClassScheduleCount: this.deleteHour // 删除课时数, 但有删除课时时，此字段不为空
            }
            if (this.courseType !== 1) { // 专业课
              params.listClassTeacher = this.listTeachers
            }
            let methodType = this.$route.query.isedit === 'edit' ? 'put' : 'post'
            if (this.$route.query.isedit === 'edit') {
              params.id = this.$route.query.id
            }
            trainApi.addClassRoom(JSON.stringify(params), methodType).then((res) => {
              this.$router.push({path: '/training/class'})
            })
          } else {
            return false
          }
        }
      })
    },
    handleAddClassItem (index, classIndex) { // 增加上课时间
      let defaultCoach = ''
      if (this.roleType === '99') {
        defaultCoach = {id: this.train_teacher_info.id, teacherName: this.train_teacher_info.name}
      }
      this.$set(this.form.classSeting[index].setArray, classIndex + 1, {
        className: '',
        classTime: '',
        classAdd: '',
        classCoach: defaultCoach,
        assistCoach: [],
        adviser: [],
        errorCoach: {
          main: [],
          assistant: [],
          adviser: []
        },
        errorMsg: '',
        isError: 2
      })
    },
    handleRemoveClassItem (index, classIndex) { // 减少上课时间
      this.form.classSeting[index].setArray.splice(classIndex, 1)
      let isError = []
      for (let i = 0; i < this.form.classSeting[index].setArray.length; i++) {
        let item = this.form.classSeting[index].setArray[i]
        if (classIndex !== i) {
          if (!(this.form.classSeting[index].setArray[classIndex].classTime[0].getTime() > item.classTime[1].getTime() || this.form.classSeting[index].setArray[classIndex].classTime[1].getTime() < item.classTime[0].getTime())) {
            isError.push(false)
          }
        }
      }
      if (isError.includes(false)) {
        this.form.classSeting[index].setArray[classIndex].errorMsg = '上下课时间重复'
        this.isError = false
        this.isSubmit = true
        this.$set(this.form.classSeting[index].setArray[classIndex], 'isError', 1)
      } else {
        this.form.classSeting[index].setArray[classIndex].errorMsg = ''
        this.isSubmit = false
        this.isError = true
        this.checkTeaching(index, classIndex)
        this.$set(this.form.classSeting[index].setArray[classIndex], 'isError', 2)
      }
    },
    handleSelectTime () { // 上课日期选择
      if (!this.form.className) {
        this.$message({
          type: 'warning',
          message: '请选择课程'
        })
        this.form.time = []
        return false
      }
      if (!this.isEditone) { // 编辑初始数据
        this.selectWeekCode = []
        for (let i = 0; i < 7; i++) {
          this.weekdays[i].isdisable = true
          this.form.classSeting[i].isShow = false
        }
      }
      let sDate, eDate // dateSpan, days
      sDate = Date.parse(this.form.time[0])
      eDate = Date.parse(this.form.time[1])
      // dateSpan = Math.abs(sDate - eDate)
      // days = Math.floor(dateSpan / (24 * 3600 * 1000))
      this.setHourData(sDate, eDate)
      this.gethourData()
      if (!this.isEditone) {
        this.handleAllCheckTeacher(1)
      }
    },
    handleBatchSet (type) { // 批量设置上课时间
      let classSeting = this.form.classSeting
      let batchSeting = this.form.batchSet
      for (let item of classSeting) {
        let setArray = item.setArray
        for (let smItem of setArray) {
          smItem.className = batchSeting.className
          smItem.classTime = batchSeting.classTime
          smItem.classAdd = batchSeting.classAdd
          smItem.classCoach = batchSeting.classCoach
          smItem.assistCoach = batchSeting.assistCoach.concat()
          smItem.adviser = batchSeting.adviser.concat()
          if (type === 'reset') {
            smItem.errorMsg = ''
          }
        }
      }
      this.dialogVisible = false
    },
    handleReset () { // 批量重置时间
      let defaultCoach = ''
      if (this.roleType === '99') {
        defaultCoach = {id: this.train_teacher_info.id, teacherName: this.train_teacher_info.name}
      }
      this.form.batchSet = {
        className: '',
        classTime: '',
        classAdd: '',
        classCoach: defaultCoach,
        assistCoach: [],
        errorCoach: {
          main: [],
          assistant: [],
          adviser: []
        },
        adviser: []
      }
      this.handleBatchSet('reset')
      this.deleteHour = 0
      this.dialogVisible = false
    },
    setHourData (sDate, eDate) { // 获得时间段的每一天日期和周几
      this.dataList = []
      let weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
      for (let i = sDate; i <= eDate; i += (24 * 3600 * 1000)) {
        let hour = parseTime(i, '{y}-{m}-{d}').split('-')
        let newdate = new Date(hour[0], parseInt(hour[1] - 1), hour[2])
        this.dataList.push({
          dateTime: parseTime(i, '{y}-{m}-{d}'),
          weekDay: weekDays[newdate.getDay()],
          weekCode: newdate.getDay() === 0 ? 7 : newdate.getDay(),
          isShow: false
        })
      }
      if (this.$route.query.weekDays) {
        this.selectWeekCode = []
        for (let i = 0; i < 7; i++) {
          this.weekdays[i].isdisable = true
          this.form.classSeting[i].isShow = false
        }
      }
      for (let item of this.dataList) {
        this.weekdays[Number(item.weekCode) - 1].isdisable = false
      }
    },
    gethourData () { // 生成最终课时数据
      this.hourList = []
      this.deleteHour = 0
      if (this.isEditone) { // 编辑时初始数据
        // console.log('初始数据')
        let hourDafault = this.defaultData.listClassSchedule
        let weekDays = ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日']
        for (let item of hourDafault) {
          this.hourList.push({
            dateTime: parseTime(item.beginDate, '{y}-{m}-{d}'),
            weekDay: weekDays[item.weekCode],
            weekCode: item.weekCode,
            monent: parseTime(item.startTime, '{h}:{i}') + '-' + parseTime(item.endTime, '{h}:{i}'),
            beginDate: item.beginDate,
            startTime: item.createTime,
            endTime: item.modifyTime,
            subjectName: item.subjectName,
            addressId: item.addressId,
            teacherId: item.teacherId,
            status: item.status
          })
        }
        this.deleteHour = this.hourList.length - this.defaultData.lessonCount
        if (this.hourList.length > 0) {
          let scope = this
          setTimeout(function () {
            scope.isEditone = false
          }, 800)
        }
        if (!this.$route.query.weekdays) {
          this.isEditone = false
        }
      } else {
        // console.log('computed')
        this.isClassSet = []
        for (let i = 0; i < this.form.classSeting.length; i++) {
          let weekCode = Number(this.form.classSeting[i].weekCode)
          if (this.form.classSeting[i].isShow !== false) {
            for (let item of this.form.classSeting[i].setArray) {
              let isRequired = []
              if (this.form.className.properties === 0) {
                delete item.className
                delete item.classCoach
              }
              for (let key in item) {
                if (key === 'errorMsg' || item[key]) {
                  isRequired.push(true)
                } else {
                  isRequired.push(false)
                }
              }
              if (isRequired.includes(false)) {
                this.isClassSet.push(false)
              } else {
                this.isClassSet.push(true)
              }
              for (let datel of this.dataList) {
                if (datel.weekCode === weekCode && item['classTime'] !== '' && item['isError'] === 2) {
                  if (!isRequired.includes(false)) {
                    this.hourList.push({
                      dateTime: datel.dateTime,
                      weekDay: datel.weekDay,
                      weekCode: datel.weekCode,
                      monent: parseTime(item['classTime'][0], '{h}:{i}') + '-' + parseTime(item['classTime'][1], '{h}:{i}'),
                      beginDate: new Date(datel.dateTime).getTime(),
                      startTime: new Date(item['classTime'][0]).getTime(),
                      endTime: new Date(item['classTime'][1]).getTime(),
                      subjectName: item.className,
                      addressId: item.classAdd ? item.classAdd.id : '',
                      teacherId: item.classCoach ? item.classCoach.id : '',
                      status: 0
                    })
                  }
                }
              }
            }
          }
        }
      }
      this.hourList = this.hourList.sort((a, b) => { // 课时按照日期排序
        return new Date(a.dateTime) - new Date(b.dateTime)
      })
      this.hourList.forEach((item, index) => {
        item.serialNo = index + 1
      })
    },
    handleDelteHour (index) { // 删除课时
      this.hourList[index].status = 1
      this.setDeleteLength()
    },
    handleCancleHour (index) { // 取消删除课时
      this.hourList[index].status = 0
      this.setDeleteLength()
    },
    setDeleteLength () { // 计算删除课时
      let hourLength = 0
      for (let item of this.hourList) {
        if (item.status === 1) {
          hourLength++
        }
      }
      this.deleteHour = hourLength
    },
    // 校验综合课的助教和顾问
    handleCheckCoach (index, classIndex, roleType) {
      // 选择了校区、班级、开课日期，周几选中且设置了 开课时间
      if (this.form.campus && this.form.type && this.form.time[0] && this.form.classSeting[index].setArray[classIndex].classTime.length) {
        let $item = this.form.classSeting[index].setArray[classIndex]
        if (roleType === 2) { // 助教
          if (this.form.classSeting[index].setArray[classIndex].assistCoach.length) {
            let teacherIdList = this.form.classSeting[index].setArray[classIndex].assistCoach.map(item => item.id)
            this.checkTeacher(teacherIdList, index, classIndex, 2)
          } else { // 没有助教
            let $errorCoach = this.getValidErrorCoach($item, 'assistant')
            if ($item.errorCoach) {
              $item.errorCoach['assistant'] = $errorCoach
            }
          }
        } else { // 顾问
          if (this.form.classSeting[index].setArray[classIndex].adviser.length) {
            let teacherIdList = this.form.classSeting[index].setArray[classIndex].adviser.map(item => item.userId)
            this.checkTeacher(teacherIdList, index, classIndex, 3)
          } else { // 没有顾问
            let $errorCoach = this.getValidErrorCoach($item, 'adviser')
            if ($item.errorCoach) {
              $item.errorCoach['adviser'] = $errorCoach
            }
          }
        }
      }
    },
    checkCoachIsNotAssit (coach, assistList) {
      let isDuplicate = false
      for (let i = 0, l = assistList.length; i < l; i++) {
        if (assistList[i] && assistList[i].id === coach.id) {
          isDuplicate = true
        }
      }
      return isDuplicate
    }
  }
}
</script>
<style lang="scss">
.add-coach{
  margin-top:20px;
}
.add_class{
  margin-top:30px;
  .set_main{
    position: relative;
    .set_button{
      position: absolute;
      left:-80px;
      top:38px;
    }
  }
  .set_all{
    margin-bottom:0;
    text-align:center;
    color:#486a67;
    text-align: left;
  }
  .el-select{
    vertical-align: top;
  }
  .el-button.is-disabled, .el-button.is-disabled:hover{
    .el-icon-plus{
      color:#e5e5e5;
    }
  }
  .el-button--text{
    color:#2a82ee;
  }
  .el-button.is-disabled,
  .el-button.is-disabled:hover{
    color:#d0cfcf;
  }
  .el-button--primary.is-disabled,
  .el-button--primary.is-disabled:hover,
  .el-button--primary.is-disabled:focus{
    color:#fff;
  }
  .time_list{
    margin-left:100px;
    font-size:12px;
    background:#fafafa;
    padding:25px 5px;
    .el-col{
      line-height:16px;
      margin-bottom:20px;
    }
    .el-button{
      font-size:12px;
      line-height:16px;
      padding:0;
      vertical-align: top;
      min-width: 20px;
    }
    .color_grea{
      color:#ccc;
    }
    .num_trip{
      display:inline-block;
      border-radius:4px;
      background:#ccc;
      text-align:center;
      min-width:35px;
      color:#333;
    }
    .class_total{
      .total_red{
        color:#f30;
      }
      .total_green{
        color:#00b28a;
      }
    }
  }
}
.multi-select-coach{
  width:314.5px!important;
  margin-top:22px;
}
.mb0{
  margin-bottom:0;
}
.pro-coach{
  width: 550px!important;
  margin-top: 15px;
}
.cike-cant{
  color: #666;
}
</style>
